﻿$(document).ready(function () {
    //when the user changes one of the input elements in a row
    $("table#EditSectionEditorsTable tr :input").live("change", function () {
        var sectionRow = $(this).parents("tr");

        //get all the section data
        var data = sectionRow.find(":input").serialize();

        //Invoke AJAX method to update this album section's editor
        $.post(pathPrefix + "Albums/UpdateAlbumSectionEditorDetails", data, function (result) {
            sectionRow.find(".successCell img").animate({ "opacity": 1 }, 1000).delay(1000).animate({ "opacity": 0 }, 1000);
        }, "json");
    });

    $("table#EditSectionEditorsTable a.btnSendMailToAlbumSectionEditor").live("click", function () {
        var sectionRow = $(this).parents("tr");

        openConfirmDialog("האם אתה בטוח שברצונך לשלוח לעורך המקטע מייל עם סיסמת העריכה שלו?", function () {
            var data = {
                "AlbumSectionId": sectionRow.find("#AlbumSectionId").val()
            };

            //Invoke AJAX method to send mail to the album section editor
            $.post(pathPrefix + "Albums/SendMailToAlbumSectionEditor", data, function (result) {
                alert(result.Value);
            }, "json");
        });

        return false;
    });

    // We use 'live' Because script is in parent dialog
    // and button is not available
    $("#btnSendMailToAllEditors").live("click", function () {

        var btn = $(this);
        var oldValue = btn.val();

        openConfirmDialog("האם אתה בטוח שברצונך לשלוח מייל לכל העורכים באלבום?", function () {
            var data = {
                "AlbumId": $("#AlbumId").val()
            }

            btn.val("מתבצעת שליחה");
            btn.attr("disabled", "disabled").addClass("disabled");

            $.post(pathPrefix + "Albums/SendPasswordMailToAllSectionEditors", data, function (result) {
                alert(result.Value);

                btn.val(oldValue);
                btn.removeAttr("disabled").removeClass("disabled");

            }, "json");
        });
    });

});